<template>
  <el-dialog
    top="-330px"
    :title="title"
    v-model="visible"
    width="490px"
    draggable
    destroy-on-close
    append-to-body
    close-on-click-modal
    @open="open"
  >
    <el-form :model="formData" label-width="80px" label-position="left">
      <el-form-item label="菜单名称">
        <el-input
          v-model="formData.name"
          autocomplete="off"
          :show-word-limit="false"
          placeholder="请输入"
          maxlength="50"
          clearable
          style="width: 330px"
        ></el-input>
      </el-form-item>
      <el-form-item label="链接" v-if="data.type === 3">
        <el-input
          v-model="formData.link"
          autocomplete="off"
          :show-word-limit="false"
          placeholder="请输入"
          maxlength="50"
          clearable
          style="width: 330px"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="onHandleClose">取消</el-button>
        <el-button type="primary" @click="onHandleConfirm">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, computed, onUnmounted, PropType } from "vue";
import mittBus from "/@/utils/mitt";

const emit = defineEmits(["update:visible"]);

const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
  data: {
    type: Object,
    default: () => {},
  },
});

const formData = ref({
  name: "",
  link: ""
});
const title = ref("");
const open = () => {
  console.log("open");
  const { type, name } = props.data;
  title.value = name;
};

const visible = computed({
  get: () => props.visible,
  set: (value) => emit("update:visible", value),
});

const updateVisible = (v: boolean) => {
  visible.value = v;
};
const onHandleClose = () => {
  updateVisible(false);
  formData.value.name = "";
};
const onHandleConfirm = () => {
  let params :any = {
    name:formData.value.name,
    type:props.data.type,
    link:formData.value.link
  }
  mittBus.emit("addNav", params);
  updateVisible(false);
  formData.value.name = "";
};
</script>
<style lang="scss" scoped></style>
